<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
	
	<table cellspacing="2" border="0" width="995">
		<tr>
			<td width="995" class="title_manager_product">Tạo video</td>
		</tr>
		<tr>
			<td>
				<table border="0" cellpadding="0" cellspacing="0" width="995">
					<tr>
						<td align="center">
							<table border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td align="center"><a href="index.php?admin=videoAdmin&do=formaddfile"><img src="images/CreateNews.gif" width="48" height="47" border="0" /></a></td>
								</tr>
								<tr>
									<td align="center" class="title_new_add"><a href="index.php?admin=videoAdmin&do=formaddfile">Tạo video</a></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>	
		</tr>
	</table>
	<form action="index.php?admin=videoAdmin&do=formaddfile" method="post" enctype="multipart/form-data">
    	<table class="reference" cellspacing="0" border="1" width="995">
        	
			<tr>
				<td colspan="2" align="center">
					<?php
						$videoname=$_POST['videoname'];
						//$videopath=$_POST['videopath'];
						
						$state=$_POST['state'];
						
						$target="../upload/video/";
						$link=$target.$_FILES['videopath']['name'];
						move_uploaded_file($_FILES['videopath']['tmp_name'],$link);
						
						$errors = array();
						
						if(isset($_POST['submit'])){
							if($videoname==''){
								$errors[] = "<font color=\"red\">Bạn chưa nhập tên video.</font>";
							}
							
							if (sizeof($errors) > 0) {
								echo "<ul>";
								foreach ($errors as $e) {
									echo "<li>$e</li>";
								}
								echo "</ul>";
							}else{
								$query="INSERT INTO videos(videoname,videopath,state) VALUES ('$videoname','$link','$state')";
								mysql_query($query);
								echo "Thêm video thành công.";	
								echo "<script>window.location='index.php?admin=videoAdmin&do=listvideo'</script>";	
								}	
							}
						
						
					?>
				</td>
			</tr>
        	<tr>
            	<td width="205" align="right"><b>Tên video:</b></td>
                <td width="700">
					<input type="text" name="videoname" size="40" /><font color="#FF0000"> * </font>
				</td>
            </tr>
			
			<tr>
                <td align="right"><b>Đường dẫn video</b></td>
                <td><input type="file" name="videopath"></td>
            </tr>
           
			 <tr>
                <td align="right"><b>Trạng thái</b></td>
                <td>
                    <select name="state">
                        <option value="on">On</option>
                        <option value="off">Off</option>
                    </select>
                </td>
            </tr>
            <tr>
            	<td></td>
                <td> <input type="submit" name="submit" value="Thêm video">
                    <input type="reset" name="reset" value="Hủy bỏ"></td>
            </tr>
        </table>
    </form>
</body>
</html>